package model

import (
	"time"
)

type Message struct {
	Id             int64  `xorm:"'id'"`
	From           int64  `xorm:"INTEGER notnull 'from'"`
	To             int64  `xorm:"INTEGER notnull 'to'"`
	Message_type   int    `xorm:"INTEGER default 1  'message_type'"`
	Content        string `xorm:"text 'content'"`
	Time           int    `xorm:"INTEGER notnull 'time'"`
	Vibration_long int    `xorm:"INTEGER 'vibration_long'"`
}

func (this *Message) AddOne(from, to int64, v_time int) error {
	var err error
	var data = &Message{
		From:           from,
		To:             to,
		Time:           int(time.Now().Unix()),
		Vibration_long: v_time,
	}
	_, err = engine.Insert(data)
	return err
}

func (this *Message) GetList(time int, to int64) (messageList map[int64]*Message, err error) {
	messageList = make(map[int64]*Message)
	err = engine.Where("\"time\">=? AND \"to\"=?", time, to).Find(&messageList)
	return messageList, err
}
